/**
 * 
 */
package com.tcc.qa.test.util;

import java.util.Set;

import org.openqa.selenium.Alert;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;

/**
 * @company CampusCruiser
 * @author Emily_Wang
 * @date 2012-5-25
 */
public class SwitchTo {
	public static WebDriver switchToIframe(WebDriver driver, String id) {
		driver.switchTo().frame(driver.findElement(By.id(id)));
		return driver;
	}

	public static WebDriver getWindowHandle(WebDriver driver) {
		for (String handle : driver.getWindowHandles()) {
			driver.switchTo().window(handle);
		}

		return driver;
	}

	public static String getWindowHandle(WebDriver driver, int index) {
		int i = 0;
		for (String handle : driver.getWindowHandles()) {
			if (i == index) {
				
				return handle;
			}
			i++;
		}
		return null;
	}

	public static void getWindowHandle(WebDriver driver, String handle) {

		driver.switchTo().window(handle);

	}
	public static WebDriver switchToDefault(WebDriver driver) {
		return driver.switchTo().defaultContent();
	}

	public static Alert switchToAlert(WebDriver driver) {
		return driver.switchTo().alert();
	}
}
